{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "x = np.arange(4,19)\n",
    "y_max = [32,33,34,34,33,31,30,29,30,29,26,23,21,25,31]\n",
    "y_min = [19,19,20,22,22,21,22,16,18,18,17,14,15,16,16]\n",
    "\n",
    "plt.plot(x,y_max)\n",
    "plt.plot(x,y_min)\n",
    "plt.show\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "x= np.arange(1,8)\n",
    "y= np.array([10770,16780,24440,30920,37670,4200,57270])\n",
    "y1= np.array([1077,1678,2444,3092,3767,4200,5727])\n",
    "bar_width = 0.30\n",
    "\n",
    "plt.bar(x,y,bottom = y1,tick_label=[\"2013\",\"2014\",\"2015\",\"2016\",\"2017\",\"2018\",\"2019\"],width=0.3)\n",
    "plt.bar(x+bar_width,y1,width=0.3,align = center)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'center' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-2-abe08931c4a3>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      7\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      8\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbar\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mbottom\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0my1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mtick_label\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"2013\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"2014\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"2015\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"2016\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"2017\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"2018\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"2019\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mwidth\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0.3\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 9\u001b[1;33m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbar\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mbar_width\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0my1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mwidth\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0.3\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0malign\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcenter\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     10\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshow\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'center' is not defined"
     ]
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hyckM3pAvVdVXWvnFJOe09ecwOBoYSTsV8B1g05hbndGY+r8U+HCS/cBdwOVJ/tMCtdwZ13tQVQfa80Hgq8AlC9Px/29M/U8BU0NHnPcwCIsFN+Z/A1cC36uqF8ff6dGNaR9+GfhBVU1X1V8BXwH+7kL1PGyM/wbuqKqLq+oy4BCwbyH6fdOHQ5IwOMe7t6p+a2jVTmBLW94C3DvLPCuTLG/LpzL4S/b98Xfc/dyx9F9Vn6yq1VW1hsEpgW9V1Qn5xDTG9+C0JO86vAxsZHCYvaDG+B78EHg+yftaaQPwzJjb7Yyr/yEf4QSfUhrjPjwHrE/yjjbnBgbn/xfUON+DJGe1578F/EMW6r1YiKvcb6QH8PcYnKd+AnisPa4C3gPsYZC6e4Az2vi/weAT3o+Al9vy6cDfBh5t8zwF/Lul1P8Rc/4SJ/ZupXG9B+9lcBj9OPA08G+XUv9t3YXARJvrvwArllj/7wD+DHj3ifr7swD78CkGH+yeAr4IvG2J9f8/GHyoeBzYsFA9+w1pSVLnTX9aSZJ0/AwHSVLHcJAkdQwHSVLHcJAkdQwHSVLHcJAkdQwHSVLn/wBCwGZVQQsEbQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "x= np.arange(1,8)\n",
    "y= np.array([10770,16780,24440,30920,37670,4200,57270])\n",
    "y1= np.array([1077,1678,2444,3092,3767,4200,5727])\n",
    "bar_width = 0.30\n",
    "\n",
    "plt.bar(x,y,bottom = y1,tick_label=[\"2013\",\"2014\",\"2015\",\"2016\",\"2017\",\"2018\",\"2019\"],width=0.3)\n",
    "plt.bar(x+bar_width,y1,width=0.3,align = center)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Accuracy: 0.7489177489177489\n"
     ]
    },
    {
     "ename": "AttributeError",
     "evalue": "module 'sklearn.tree' has no attribute 'plot_tree'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-3-ec5ab03dacfb>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     39\u001b[0m \u001b[0mtarget_names\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mpima\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'label'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0munique\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtolist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     40\u001b[0m \u001b[0mfig\u001b[0m\u001b[1;33m=\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfigure\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mfigsize\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m50\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m40\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 41\u001b[1;33m \u001b[0mtree\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplot_tree\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mclf\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mfeature_names\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfeature_names\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mclass_names\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'0'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'1'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mfilled\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     42\u001b[0m \u001b[0mfig\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshow\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     43\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mAttributeError\u001b[0m: module 'sklearn.tree' has no attribute 'plot_tree'"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<Figure size 3600x2880 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from sklearn.tree import DecisionTreeClassifier\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "from sklearn.tree import  export_graphviz\n",
    "from sklearn.tree import DecisionTreeClassifier\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn import metrics\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn import tree\n",
    "from sklearn.model_selection import GridSearchCV,RandomizedSearchCV\n",
    "from sklearn.metrics import accuracy_score\n",
    "\n",
    "# data = pd.read_csv('diabetes.csv')\n",
    "# df = pd.DataFrame(data)\n",
    "# X = df.iloc[:,0:6]\n",
    "# y = df.iloc[:,7]\n",
    "# # print(X,y)\n",
    "# X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.3,random_state=42)\n",
    "#\n",
    "# tree = DecisionTreeClassifier(criterion=\"entropy\",random_state=0,max_depth=2)\n",
    "# tree.fit(X_train,y_train)\n",
    "#\n",
    "# print('accuracy of descion-tree on train:{:.3f}'.format(tree.score(X_train,y_train)))\n",
    "# print('accuracy of descion-tree on test:{:.3f}'.format(tree.score(X_test,y_test)))\n",
    "\n",
    "\n",
    "col_names=['pregnant','glucose','bp','skin','insulin','bmi','pedigree','age','label']\n",
    "pima=pd.read_csv('diabetes.csv',header=None,names=col_names)\n",
    "feature_cols=['pregnant','insulin','bmi','age','glucose','bp','pedigree']\n",
    "X=pima[feature_cols]\n",
    "y=pima.label\n",
    "X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.3,random_state=1)\n",
    "clf = DecisionTreeClassifier(criterion='entropy')\n",
    "clf=clf.fit(X_train,y_train)\n",
    "y_pred=clf.predict(X_test)\n",
    "print(\"Accuracy:\",metrics.accuracy_score(y_test,y_pred))\n",
    "feature_names=feature_cols\n",
    "target_names=pima['label'].unique().tolist()\n",
    "fig= plt.figure (figsize=(50,40))\n",
    "tree.plot_tree(clf,feature_names=feature_names,class_names=['0','1'],filled=True)\n",
    "fig.show()\n",
    "\n",
    "param_grid = {\n",
    "    'max_depth':[3,5,10],\n",
    "    'max_feature':[2,3],\n",
    "    'min_samples_leaf':[1,2,3],\n",
    "    'min_samples_split':[2,3,4]\n",
    "}\n",
    "\n",
    "clf = DecisionTreeClassifier(criterion='entropy')\n",
    "\n",
    "grid_search = GridSearchCV(estimator=clf,param_grid=param_grid,cv=3,n_jobs=-1,verbose=2)\n",
    "Random_search = RandomizedSearchCV(estimator=clf,param_distributions=param_grid,cv=3,n_jobs=-1,verbose=2)\n",
    "\n",
    "\n",
    "grid_search.fit(X_train,y_train)\n",
    "pridict_train1 = grid_search.predict(X_train)\n",
    "print('Target on train data',pridict_train1)\n",
    "accuracy_train1 = accuracy_score(y_train,pridict_train1)\n",
    "print('Gridsearchaccuracy_score on train dataset:',accuracy_train1)\n",
    "Random_search.fit(X_train,y_train)\n",
    "pridict_train2=Random_search.predict(X_train)\n",
    "print('Target on train data',pridict_train2)\n",
    "\n",
    "print(grid_search.best_params_)\n",
    "print(grid_search.best_estimator_)\n",
    "\n",
    "print(Random_search.best_params_)\n",
    "print(Random_search.best_estimator_)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
